package com.corner.model.cornerservice.service;


import com.corner.model.cornerservice.service.exception.BaseException;

import java.util.List;

import retrofit.ErrorHandler;
import retrofit.RetrofitError;
import retrofit.client.Header;

public class MyErrorHandler implements ErrorHandler {

    @Override
    public BaseException handleError(RetrofitError arg0) {
        if (arg0.getResponse() != null) {
            List<Header> headers = arg0.getResponse().getHeaders();
            if (headers != null && !headers.isEmpty()) {
                for (Header header : headers) {
                    if ("code".equals(header.getName())) {
                        return new BaseException(header.getValue());
                    }
                }
            }
        } else {
            arg0.printStackTrace();
        }
        return new BaseException(BaseException.UnKnownError);
    }
}
